package io.stream;

import framework.AbstractTest;
import io.reader.BufferedInputFile;
import utils.Log;

import java.io.*;

/**
 * Created by shane on 2018/5/20.
 */
public class StoringAndRecoveringData extends AbstractTest {
    protected static final String TAG = StoringAndRecoveringData.class.getName();

    @Override
    public void test(String[] args) {
        super.test(args);

        String output = getDefOutputFile(args);

        try {
            DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(output)));
            out.writeDouble(3.14159);
            out.writeUTF("this is pi");
            out.writeDouble(1.41413);
            out.writeUTF("square root of 2");
            out.close();

            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(output)));
            Log.v(in.readDouble());
            Log.v(in.readUTF());
            Log.v(in.readDouble());
            Log.v(in.readUTF());
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected String getTag() {
        return TAG;
    }
}
